package com.crm.reports;

import java.awt.Desktop;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.JOptionPane;

import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanArrayDataSource;

import com.crm.beans.QuotParts;
import org.apache.log4j.Logger;
public class JRPurchaseOrder {
	private static final Logger logger=Logger.getLogger(JRPurchaseOrder.class.getName());
	
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		String refno="KK/CP/1/19-12-2011";
		  Map parameters = new HashMap();
		  parameters.put("referenceno", "KK/CP/1/12-09-2012");
		  parameters.put("CompanyAddress", "KKCircuits & Equipments,SBI Building,AnandBagh,Malkajgiri,Hyderabad-500042");
		  parameters.put("from", "KKCircuits & Equipments");
		  parameters.put("pono", "KKCE/1234");
		  parameters.put("totalword", "ten thousand rupees only");
		  parameters.put("totalcost", "10000");
		  parameters.put("billto", "ECIL \n" +
			  		"Anandbagh \n" +
			  		"Malkajgiri \n" +
			  		"Secunderabad \n" +
			  		"500072");
		  parameters.put("shipto", "ECIL \n" +
			  		"Anandbagh \n" +
			  		"Malkajgiri \n" +
			  		"Secunderabad \n" +
			  		"500072");
		  parameters.put("supplieraddress", "ECIL \n" +
		  		"Anandbagh \n" +
		  		"Malkajgiri \n" +
		  		"Secunderabad \n" +
		  		"500072");
		  parameters.put("terms",
				  "1 Vat @4% EXTRA.\n" +
				  "2 Validity: 30DAYS \n" +
				  "3 Waranty: NOT APPLICABLE\n" +
				  "4 Payment:  100% within 15 Days from the date of receipt of material at your stores,else interest @ 2.5%/month needs to be paid by your organisation\n" +
				  "5  Prices are valid for quoted quantities only.\n" +
				  "6  Quoted lead time is as of now only.\n" +
				  "7 Order should be placed on: KK Circuits & equipments\n"+
				  "8 Order should be placed on: KK Circuits & equipments\n"+
				  "9 Order should be placed on: KK Circuits & equipments\n"+
				  "10 Order should be placed on: KK Circuits & equipments\n"+
				  "11 Order should be placed on: KK Circuits & equipments\n"+
				  "12 Order should be placed on: KK Circuits & equipments\n"+
				  "13 Order should be placed on: KK Circuits & equipments\n" +
				  "14 Order should be placed on: KK Circuits & equipments\n" +
				  "15 Order should be placed on: KK Circuits & equipments\n" +
				  "16 Order should be placed on: KK Circuits & equipments\n" +
				  "17 Order should be placed on: KK Circuits & equipments\n" +
				  "18 Order should be placed on: KK Circuits & equipments\n" +
				  "19 Order should be placed on: KK Circuits & equipments\n" +
				  "20 Order should be placed on: KK Circuits & equipments\n" +
				  "21 Order should be placed on: KK Circuits & equipments\n" +
				  "22 Order should be placed on: KK Circuits & equipments\n" +
				  "23 Order should be placed on: KK Circuits & equipments\n" +
				  "24 Order should be placed on: KK Circuits & equipments\n" +
				  "25 Order should be placed on: KK Circuits & equipments\n" +
				  "26 Order should be placed on: KK Circuits & equipments\n"
				  );
		  
		  List<QuotParts> l=new ArrayList<QuotParts>();
		  QuotParts qp=new QuotParts();
		  qp.sno="1";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="2";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="3";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="4";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="5";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="6";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="7";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="8";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="9";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="10";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="11";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="12";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="13";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="14";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		  
		  
		  qp=new QuotParts();
		  qp.sno="15";
		  qp.partNo="er2323";
		  qp.desc="abcd";
		  qp.make="honda";
		  qp.qty="10";
		  qp.unitPrice="10";
		  qp.subtotal="1000";
		  l.add(qp);
		 
		  
		 
		  
		  
		  
		runReport("D:/work/crmWeb/WebContent/WEB-INF/classes/reports/po.jasper",refno, parameters, l.toArray());
		
		}

	public static void runReport(String repName,String refno,Map params,Object[] qparts) throws Exception{
		  long start = System.currentTimeMillis();
		  //Preparing parameters
		   
		 JasperPrint print =JasperFillManager.fillReport(repName,params,new JRBeanArrayDataSource(qparts));
		 
		 
		 OutputStream output = new FileOutputStream(new File(" Purchase Order.pdf"));
		  JasperExportManager.exportReportToPdfStream(print, output); 
		  output.close();
		  //Thread.sleep(2000);
		  Desktop.getDesktop().open(new File(" Purchase Order.pdf"));
		  
		  System.err.println("Filling time : " + (System.currentTimeMillis() - start));
		
	}
}
